Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MiniJinja for templating #83

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

aperezdc
Copy link
Contributor

This patch series replaces the custom templating from Hebbot with MiniJinja, which is a complete templating engine for Rust based on the popular Jinja2 one. This makes Hebbot output much more flexible and customizable, and allows to producing all kind of text-based output formats.

The patch set starts by updating the dependencies, which was needed in order to satisfy some of the minimum versions of some crates required by MiniJinja; then it adds the new templating code and removes the old one iteratively. Lastly, example configurations and documentation are brought up-to-date.

The updated example configuration should produce (almost) the same output as before.

@aperezdc aperezdc force-pushed the minijinja branch 2 times, most recently from e913b61 to be3f8f6 Compare September 11, 2024 10:21
@MoralCode
Copy link
Contributor

Are there specific kinds of flexibility this may enable for existing hebbot users that isn't currently possible? it possible this could be done behind some kind of feature flag or opt-in in the config (maybe by adding jekyll-style front-matter to the top of the markdown files) so that existing users can opt out if they dont need the extra features?

Personally I love the simplicity of the current markdown templates as they currently are and haven't yet run into a situation where they weren't sufficient. The new sample markdown in this MR feels to me like a very sharp/sudden change that existing users who are used to the simplicity of the current markdown templating may not find worthwhile to migrate to unless they need to include some kind of additional plugins or other advanced things that are only possible with minijinja

@aperezdc
Copy link
Contributor Author

aperezdc commented Oct 1, 2024

@MoralCode My initial motivation was being able to customize date formats because I wanted to use Hebbot for monthly updates. Then I figured that bringing in a template engine would allow me to generate HTML (or any other textual format) as well without needing to hardcode the formatting in src/render.rs.

src/bot.rs Outdated Show resolved Hide resolved
src/render.rs Outdated Show resolved Hide resolved
@aperezdc aperezdc force-pushed the minijinja branch 4 times, most recently from 1395eff to 8dc9502 Compare November 24, 2024 12:01
The render_template() function is only used once, and after making the
minijinja::Environment instance a static singleton it does not contain
much code, so it makes more sense to invoke the template rendering
directly instead of going through an additional function call.
Bubble up Jinja errors to the caller, and send a message with the error
to the admin room on failures, instead of letting the process crash at
.unwrap() calls.
Use the "random" filter from the minijinja-contrib crate, instead
of a custom one. This removes a little bit of code from render.rs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants